package ${package.Controller};

import com.gomcarter.frameworks.base.pager.DefaultPager;
import ${custom_package_dto}.${custom_class_Dto};
import ${custom_package_manager}.${custom_class_Manager};
import ${custom_package_params}.${custom_class_CreateParam};
import ${custom_package_params}.${custom_class_QueryParam};
import ${custom_package_params}.${custom_class_UpdateParam};
import com.yifeng.repo.base.api.PageResult;
import com.yifeng.repo.base.constant.BaseConstant;
import com.yifeng.repo.base.params.IdParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Slf4j
@Validated
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("${custom_request_mapping}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
    /**
     * 【温馨提示】控制层代码规范
     * 1、Controller层负责参数校验、路由鉴权等。
     * 2、建议按照请求终端类型区分不同Controller。
     * 3、建议仅注入Manager层类，不注入Service层类。
     */

    @Resource
    private ${custom_class_Manager} ${custom_Manager_instance_name};

    /**
     * 主键查询：${table.comment!}
     * @param ${custom_idName} ${custom_idComment}
     * @return ${table.comment!}对象
     */
    @GetMapping(value = "getById")
    public ${custom_class_Dto} getById(@NotNull(message = "${custom_idName}不能为空") @RequestParam("${custom_idName}") ${custom_idSimpleType} ${custom_idName}) {
        return ${custom_Manager_instance_name}.getById(${custom_idName});
    }

    /**
     * 列表查询：${table.comment!}
     * @param param 查询条件
     * @param pager  分页条件
     * @return ${table.comment!}列表
     */
    @GetMapping(value = "list")
    public List<${custom_class_Dto}> list(${custom_class_QueryParam} param, DefaultPager pager) {
        return ${custom_Manager_instance_name}.list(param, pager);
    }

    /**
     * 偏移量查询：${table.comment!}
     * @param ${custom_offsetIdName} ${custom_idComment} 偏移量
     * @return ${table.comment!}列表
     */
    @GetMapping(value = "listByOffsetId")
    public List<${custom_class_Dto}> listByOffsetId(@NotNull(message = "${custom_offsetIdName}不能为空") @RequestParam("${custom_offsetIdName}") ${custom_idSimpleType} ${custom_offsetIdName}) {
        return ${custom_Manager_instance_name}.listByOffsetId(${custom_offsetIdName}, BaseConstant.PAGE_SIZE_LIMIT);
    }

    /**
     * 查询总数：${table.comment!}
     * @param param 查询条件
     * @return 总记录数
     */
    @GetMapping(value = "count")
    public Long count(${custom_class_QueryParam} param) {
        return ${custom_Manager_instance_name}.count(param);
    }

    /**
     * 检查是否存在：${table.comment!}
     * @param param 查询条件
     * @return 是否存在
     */
    @GetMapping(value = "contains")
    public Boolean contains(${custom_class_QueryParam} param) {
        return ${custom_Manager_instance_name}.contains(param);
    }

    /**
    * 分页查询：${table.comment!}
    * @param param 查询条件
    * @param pager  分页条件
    * @return ${table.comment!}分页
    */
    @GetMapping(value = "listPage")
    public PageResult<${custom_class_Dto}> listPage(${custom_class_QueryParam} param, DefaultPager pager) {
        return ${custom_Manager_instance_name}.listPage(param, pager);
    }

    /**
     * 新增数据：${table.comment!}
     * @param param 新增条件
     * @return ${custom_idComment}
     */
    @PostMapping(value = "create")
    public ${custom_idSimpleType} create(@RequestBody @Validated ${custom_class_CreateParam} param) {
        return ${custom_Manager_instance_name}.create(param);
    }

    /**
     * 修改数据：${table.comment!}
     * @param param 修改条件
     * @return 是否修改成功
     */
    @PostMapping(value = "update")
    public boolean update(@RequestBody @Validated ${custom_class_UpdateParam} param) {
        return ${custom_Manager_instance_name}.update(param);
    }

    /**
     * 删除数据：${table.comment!}
     * @param param 删除条件
     * @return 是否删除成功
     */
    @PostMapping(value = "delete")
    public boolean delete(@RequestBody @Validated IdParam param) {
        return ${custom_Manager_instance_name}.delete(param);
    }
}
</#if>
